<?
/* @author Udo Schroeter <udo.schroeter@gmail.com>
 * @license dual license: LGPL / commercial use license
 */ 

class TalkModel extends AGModel
{
  function __construct($modelName) 
  {
    parent::__construct($modelName);
  }
  
  function loadTalkFromActionDS(&$act, $tp)
  {
    include_once('models/character.model.php');
     
    $this->talk = TextToStringList($act['a_text']);
    $this->properties = &$act['properties'];
  
    $this->startId = getDefault($this->properties['begin'], 1);
    $this->currentId = getDefault($tp, $this->startId);  
    
    $this->mob = new CharacterModel('mob', $this, $this->properties['mob']);
    $this->image = getDefault($act['a_icon'], $this->mob->charDS['c_icon']);
  }
 
  function loadCurrentOptions()
  {
    include_once('models/game.model.php');
    eval($this->talk[$this->currentId.'.update']);
    
    foreach(explode(',', $this->talk[$this->currentId.'.options']) as $option)
    {
      $talkId = CutSegment('>', $option);
      $condition = $this->talk[$this->currentId.'.'.$talkId.'.if'];
      if ($condition == '' || GameModel::meetsPrerequisite($condition, $this->character))
        if ($option != '')
          $this->options[$talkId] = $option;
    }
    if (isset($this->properties['cancel']))
    {
      $this->options['cancel'] = 'cancel';
      $this->talk[$this->currentId.'.cancel'] = $this->properties['cancel'];
    }   
  }
 
}
 
?>